package com.sromku.bugsnag.utils;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
/**
* @author sromku
*/
public class SelectionHelper {
public static IResource extractSelection(ISelection sel) {
if (!(sel instanceof IStructuredSelection)) {
return null;
}
IStructuredSelection ss = (IStructuredSelection) sel;
Object element = ss.getFirstElement();
if (element instanceof IResource) {
return (IResource) element;
}
if (!(element instanceof IAdaptable)) {
return null;
}
IAdaptable adaptable = (IAdaptable) element;
Object adapter = adaptable.getAdapter(IResource.class);
return (IResource) adapter;
}
}